// 登录模块
import { makeAutoObservable } from "mobx"
import { axios_request, setToken, getToken, clearToken } from '@/utils'


class LoginStore {
  token = getToken() || ""
  constructor() {
    makeAutoObservable(this)
  }
  // 登录
  login = async ({ username, password }) => {
    const res = await axios_request.post('login', {username, password})

    this.token = res.data.token
    setToken(this.token)
  }

   // 退出登录
  loginOut = async() => {
    await axios_request.get('logout')
    this.token = ''
    clearToken()
  }

}
export default LoginStore